package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jss.lanouhn.fristapp.Interface.OnItemClickLister;
import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.modles.CategoryStrategyNormal;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/8/25.
 */
public class CategoryStrategyNormalAdapter extends RecyclerView.Adapter<CategoryStrategyNormalAdapter.NormalViewHolder> {
    private Context mContext;
    private CategoryStrategyNormal categoryStrategyNormal;
    private int flag,count;
    private OnItemClickLister onItemClickLister;
    public void setOnItemClickLister(OnItemClickLister onItemClickLister){
        this.onItemClickLister=onItemClickLister;
    }

    public CategoryStrategyNormalAdapter(int count, int flag, CategoryStrategyNormal categoryStrategyNormal, Context mContext) {
        this.count = count;
        this.flag = flag;
        this.categoryStrategyNormal = categoryStrategyNormal;
        this.mContext = mContext;
    }

    @Override
    public NormalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_category_strategy_normal, null);
        NormalViewHolder holder = new NormalViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final NormalViewHolder holder, int position) {

        CategoryStrategyNormal.DataBean.ChannelGroupsBean.ChannelsBean channelsBean=
                categoryStrategyNormal.getData().getChannel_groups().get(flag).getChannels().get(position);
        Picasso.with(mContext).load(channelsBean.getCover_image_url()).into(holder.imageView);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos=holder.getLayoutPosition();
                onItemClickLister.onItemClick(holder.itemView,pos);
            }
        });
    }

    @Override
    public int getItemCount() {
        int xixi=0;
        if(count==1){
            xixi=6;
        }
        else if(count==2){
            xixi=categoryStrategyNormal.getData().getChannel_groups().get(flag).getChannels().size();
        }
        return xixi;
    }

    public class NormalViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;

        public NormalViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.riv_item_strategy_normal);


        }
    }
}
